/*============================================================================
MAIN KERNEL CODE

EXPORTS:
void kprintf(const char *fmt, ...);
============================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h> /* va_list, va_start(), va_end() */
#include <string.h> /* NULL */
#include <x86.h> /* disable() */
#include <_printf.h>
#include "_krnl.h" /* regs_t */
#ifdef __cplusplus
}
#endif

/* IMPORTS
from KSTART.ASM */
void getvect(vector_t *v, unsigned vect_num);
void setvect(vector_t *v, unsigned vect_num);

/* from VIDEO.C */
extern console_t _vc[];

void blink(void);
void putch(unsigned c);
void init_video(void);

/* from KBD.C */
void keyboard_irq(void);
void init_keyboard(void);

/* from SCHED.C */
void schedule(void);
void init_tasks(void);

/* from DEBUG.C */
void dump_regs(regs_t *regs);


/*****************************************************************************
*****************************************************************************/
/*****************************************************************/


static void init_8259s(void)
{
        static const unsigned irq0_int = 0x20, irq8_int = 0x28;
/**/

/* Initialization Control Word #1 (ICW1) */
        outportb(0x18, 0x11);
        outportb(0xA0, 0x11);
/* ICW2:
route IRQs 0-7 to INTs 20h-27h */
        outportb(0x10, irq0_int);
/* route IRQs 8-15 to INTs 28h-2Fh */
        outportb(0xA1, irq8_int);
/* ICW3 */
        outportb(0x20, 0x04);
        outportb(0xA1, 0x02);
/* ICW4 */
        outportb(0x20, 0x01);
        outportb(0xA1, 0x01);
/* enable IRQ0 (timer) and IRQ1 (keyboard) */
        outportb(0x20, ~0x03);
        outportb(0xA1, ~0x00);
}


